GridStatistics Module

History

current version 1.2 - 24th Jan 2020

version date comment
1.0 19/Dec/2016 routines moved from GridOperations module
1.1 04/Sep/2018 GetCV to compute coefficient of variation of a grid
1.2 24/Jan/2020 Added subroutine UniqueValues to retrieve a list of distinct values from a grid_integer

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Module Description:

library to compute grids statistics



Interfaces

public interface CountCells

  • private function CountCellsFloat(grid) result(count)

    count number of cells different from nodata

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid

    Return Value integer(kind=short)

  • private function CountCellsInteger(grid) result(count)

    count number of cells different from nodata

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid

    Return Value integer(kind=short)

public interface GetBias

  • private function GetBiasFloat(grid1, grid2, maskReal, maskInteger, rbias) result(bias)

    compute mean Bias between two grids real optional argument: mask: compute Bias only on assigned mask rbias: compute relative Bias

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid1
    type(grid_real), intent(in) :: grid2
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger
    logical, intent(in), optional :: rbias

    Return Value real(kind=float)

public interface GetCV

  • public function GetCVofGridFloat(grid, maskReal, maskInteger) result(cv)

    compute coefficient of variation of grid_real eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

public interface GetMax

  • private function GetMaxOfGridFloat(grid, maskReal, maskInteger) result(max)

    compute maximum of grid_real eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

  • private function GetMaxOfGridInteger(grid, maskReal, maskInteger) result(max)

    compute maximum of grid_integer eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value integer(kind=long)

public interface GetMean

  • private function GetMeanOfGridFloat(grid, maskReal, maskInteger) result(mean)

    compute mean of grid_real eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

  • private function GetMeanOfGridInteger(grid, maskReal, maskInteger) result(mean)

    compute mean of grid_integer eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

public interface GetMin

  • private function GetMinOfGridFloat(grid, maskReal, maskInteger) result(min)

    compute minimum of grid_real eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

  • private function GetMinOfGridInteger(grid, maskReal, maskInteger) result(min)

    compute minimum of grid_integer eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value integer(kind=long)

public interface GetNSE

  • public function GetNSEfloat(grid1, grid2, maskReal, maskInteger, normalized) result(nash)

    compute Nash and Sutcliffe efficiency index, equivalent to coefficient of determination. optional argument: mask: compute RMSE only on assigned mask nrmse: compute normalized Nash efficiency


    References:
    Nash, J. E. and J. V. Sutcliffe (1970), River flow forecasting through conceptual models part I — A discussion of principles, Journal of Hydrology, 10 (3), 282–290.

    Moriasi, D. N.; Arnold, J. G.; Van Liew, M. W.; Bingner,R. L.; Harmel, R. D.; Veith, T. L. (2007), "Model Evaluation Guidelines for Systematic Quantification of Accuracy in Watershed Simulations", Transactions of the ASABE, 50 (3), 885–900. http://swat.tamu.edu/media/1312/moriasimodeleval.pdf

    Nossent, J., Bauwens, W., Application of a normalized Nash-Sutcliffe efficiency to improve the accuracy of the Sobol’ sensitivity analysis of a hydrological model Geophysical Research Abstracts Vol. 14, EGU2012-237, 2012 EGU General Assembly 2012

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid1
    type(grid_real), intent(in) :: grid2
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger
    logical, intent(in), optional :: normalized

    Return Value real(kind=float)

public interface GetR2

  • private function GetR2float(grid1, grid2, maskReal, maskInteger) result(r2)

    compute R2, square of the Pearson correlation coefficient optional argument: mask: compute RMSE only on assigned mask


    References:
    Karl Pearson (20 June 1895) "Notes on regression and inheritance in the case of two parents," Proceedings of the Royal Society of London, 58 : 240–242

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid1
    type(grid_real), intent(in) :: grid2
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

public interface GetRMSE

  • private function GetRMSEfloat(grid1, grid2, maskReal, maskInteger, nrmse) result(rmse)

    compute Root Mean Square Error between two grids real optional argument: mask: compute RMSE only on assigned mask nrmse: compute Normalizes Root Mean Square Error

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid1
    type(grid_real), intent(in) :: grid2
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger
    logical, intent(in), optional :: nrmse

    Return Value real(kind=float)

public interface GetStDev

  • private function GetStDevOfGridFloat(grid, maskReal, maskInteger) result(stDev)

    compute unbiased standard deviation of grid_real optionally constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

  • private function GetStDevOfGridInteger(grid, maskReal, maskInteger) result(stDev)

    compute unbiased standard deviation of grid_integer optionally constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

public interface GetSum

  • private function GetSumOfGridFloat(grid, maskReal, maskInteger) result(sum)

    compute sum of grid_real eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value real(kind=float)

  • private function GetSumOfGridInteger(grid, maskReal, maskInteger) result(sum)

    compute sum of grid_integer eventually constrained to a mask

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    type(grid_real), intent(in), optional :: maskReal
    type(grid_integer), intent(in), optional :: maskInteger

    Return Value integer(kind=long)

public interface MinMaxNormalization

  • private subroutine MinMaxNormalizationFloat(gridIn, gridOut, min, max)

    performs a linear transformation on the original data values. Suppose that minX and maxX are the minimum and maximum of feature X. We would like to map interval [minX, maxX] into a new interval [new_minX, new_maxX]. Consequently, every value v from the original interval will be mapped into value new_v following formula:

    new_v = (v - minX) / (maxX - minX) * (new_maxX - new_minX) + new_minX

    If new_minX and new_maxX are not given values are mapped to [0,1] interval


    References:
    Hann, J., Kamber, M. (2000). Data Mining: Concepts and Techniques. Morgan Kaufman Publishers.

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: gridIn
    type(grid_real), intent(inout) :: gridOut
    real(kind=float), intent(in), optional :: min
    real(kind=float), intent(in), optional :: max

public interface UniqueValues

  • public subroutine UniqueValuesOfGridInteger(grid, values)

    Description return a vector of distinct values from a grid_integer

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid
    integer(kind=short), intent(out), ALLOCATABLE :: values(:)

Functions

public function GetCVofGridFloat(grid, maskReal, maskInteger) result(cv)

compute coefficient of variation of grid_real eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

public function GetNSEfloat(grid1, grid2, maskReal, maskInteger, normalized) result(nash)

compute Nash and Sutcliffe efficiency index, equivalent to coefficient of determination. optional argument: mask: compute RMSE only on assigned mask nrmse: compute normalized Nash efficiency

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid1
type(grid_real), intent(in) :: grid2
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger
logical, intent(in), optional :: normalized

Return Value real(kind=float)

private function CountCellsFloat(grid) result(count)

count number of cells different from nodata

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid

Return Value integer(kind=short)

private function CountCellsInteger(grid) result(count)

count number of cells different from nodata

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid

Return Value integer(kind=short)

private function GetBiasFloat(grid1, grid2, maskReal, maskInteger, rbias) result(bias)

compute mean Bias between two grids real optional argument: mask: compute Bias only on assigned mask rbias: compute relative Bias

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid1
type(grid_real), intent(in) :: grid2
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger
logical, intent(in), optional :: rbias

Return Value real(kind=float)

private function GetMaxOfGridFloat(grid, maskReal, maskInteger) result(max)

compute maximum of grid_real eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetMaxOfGridInteger(grid, maskReal, maskInteger) result(max)

compute maximum of grid_integer eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value integer(kind=long)

private function GetMeanOfGridFloat(grid, maskReal, maskInteger) result(mean)

compute mean of grid_real eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetMeanOfGridInteger(grid, maskReal, maskInteger) result(mean)

compute mean of grid_integer eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetMinOfGridFloat(grid, maskReal, maskInteger) result(min)

compute minimum of grid_real eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetMinOfGridInteger(grid, maskReal, maskInteger) result(min)

compute minimum of grid_integer eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value integer(kind=long)

private function GetR2float(grid1, grid2, maskReal, maskInteger) result(r2)

compute R2, square of the Pearson correlation coefficient optional argument: mask: compute RMSE only on assigned mask

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid1
type(grid_real), intent(in) :: grid2
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetRMSEfloat(grid1, grid2, maskReal, maskInteger, nrmse) result(rmse)

compute Root Mean Square Error between two grids real optional argument: mask: compute RMSE only on assigned mask nrmse: compute Normalizes Root Mean Square Error

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid1
type(grid_real), intent(in) :: grid2
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger
logical, intent(in), optional :: nrmse

Return Value real(kind=float)

private function GetStDevOfGridFloat(grid, maskReal, maskInteger) result(stDev)

compute unbiased standard deviation of grid_real optionally constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetStDevOfGridInteger(grid, maskReal, maskInteger) result(stDev)

compute unbiased standard deviation of grid_integer optionally constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetSumOfGridFloat(grid, maskReal, maskInteger) result(sum)

compute sum of grid_real eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value real(kind=float)

private function GetSumOfGridInteger(grid, maskReal, maskInteger) result(sum)

compute sum of grid_integer eventually constrained to a mask

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
type(grid_real), intent(in), optional :: maskReal
type(grid_integer), intent(in), optional :: maskInteger

Return Value integer(kind=long)


Subroutines

public subroutine UniqueValuesOfGridInteger(grid, values)

Description return a vector of distinct values from a grid_integer

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
integer(kind=short), intent(out), ALLOCATABLE :: values(:)

public subroutine ZscoreNormalizationFloat(gridIn, gridOut)

also called zero-mean normalization. The values of attribute X are normalized using the mean and standard deviation of X. A new value new_v is obtained using the following expression:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: gridIn
type(grid_real), intent(inout) :: gridOut

private subroutine MinMaxNormalizationFloat(gridIn, gridOut, min, max)

performs a linear transformation on the original data values. Suppose that minX and maxX are the minimum and maximum of feature X. We would like to map interval [minX, maxX] into a new interval [new_minX, new_maxX]. Consequently, every value v from the original interval will be mapped into value new_v following formula:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: gridIn
type(grid_real), intent(inout) :: gridOut
real(kind=float), intent(in), optional :: min
real(kind=float), intent(in), optional :: max